package com.augurit.common.syslog.web;

import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springside.modules.orm.Page;

import com.augurit.common.base.action.CrudActionSupport;
import com.augurit.common.base.action.ExtCrudActionSupport;
import com.augurit.common.syslog.service.ISysTraceLogService;
import com.augurit.common.syslog.web.form.SysTraceLogForm;
import com.augurit.common.util.ExtUtils;

@SuppressWarnings("serial")
@Results({
	@Result(name = CrudActionSupport.RELOAD, location = "sys-trace-log.action", type = "redirect"),
	@Result(name = CrudActionSupport.SUCCESS, location = "/common/syslog/sys-trace-log.jsp")
})
public class SysTraceLogAction extends ExtCrudActionSupport<SysTraceLogForm>{

	@Autowired
	private ISysTraceLogService sysTraceLogService;

	private SysTraceLogForm form;
	private Long id;
	private Long[] ids;
	private Page<SysTraceLogForm> page = new Page<SysTraceLogForm>();


	/**
	 * 分页查询
	 */
	@Override
	public String list() throws Exception {
		ExtUtils.initPageFromExtGridParam(this.getRequest(), page);
		sysTraceLogService.search(page, form);
		this.extRenderGridJson(page);
		return null;
	}

	/**
	 * 新增或修改
	 */
	@Override
	public String input() throws Exception {
		this.extRenderFormJson(form);
		return null;
	}

	/**
	 * 保存新增或者修改的Form对象
	 */
	@Override
	public String save() throws Exception {
		sysTraceLogService.save(form);
		this.extRenderSuccess();
		return null;
	}

	/**
	 * 删除记录
	 */
	@Override
	public String delete() throws Exception {
		if(ids != null && ids.length > 0){
			for(Long id : ids){
				sysTraceLogService.delete(id);
			}
		}
		return null;
	}
	
	/**
	 * 准备页面模型
	 */
	@Override
	protected void prepareModel() throws Exception {
		if(id != null){
			form = sysTraceLogService.get(id);
		}
		else
			form = new SysTraceLogForm();
	}
	
	public SysTraceLogForm getModel() {
		return form;
	}
	
	// 属性getter和setter方法
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}
	
	public Long[] getIds() {
		return ids;
	}

	public void setIds(Long[] ids) {
		this.ids = ids;
	}

	public Page<SysTraceLogForm> getPage() {
		return page;
	}


	public void setPage(Page<SysTraceLogForm> page) {
		this.page = page;
	}
}
